import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import java.security.Key;
import java.util.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: lv
 * Date: 2023-03-17
 * Time: 19:50
 */
public class TestDemo {

    //找出数据中第一个重复的元素
    public static int func3(int[] array){
        Set<Integer> set=new HashSet<>();
        for (int x:array) {
            if(set.contains(x)){
                return x;
            }
            set.add(x);
        }
        return -1;
    }


    //将数据中的数据去重
    public static Set<Integer> func2(int[] array){
        Set<Integer> set=new HashSet<>();
        for (int x:array) {
                set.add(x);
            }
        return set;
    }

    //统计每个数据出现的次数
    //key是关键字，value是出现的次数
    public static Map<Integer,Integer> func(int[] array){  //统计重复出现的次数
        Map<Integer,Integer> map=new HashMap<>();
        //判断array中的元素是否在map中，如果不在就是1，再就是在原来的基础上再加1
        for (int x:array) {
            if(map.get(x)==null){
                map.put(x,1);
            }else{
                int val=map.get(x);
                map.put(x,val+1);
            }
        }
        return map;
    }


    public static void main3(String[] args) {
        int[] array=new int[1_0000];
        Random random=new Random();
        for (int i = 0; i < array.length; i++) {
            array[i]=random.nextInt(100)+1;
        }
        /*Map<Integer,Integer> map=func(array);
        System.out.println(map);*/
        /*Set<Integer> set=func2(array);
        System.out.println(set);*/
        int ret=func3(array);
        System.out.println(ret);
    }

    public static void main(String[] args) {
        Set<Integer> set=new HashSet<>();//Set自动去重
        set.add(1);
        set.add(2);
        set.add(3);
        //set.add(2);
        //System.out.println(set);
        Iterator<Integer> iterator=set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
        /*int tmp=iterator.next();
        System.out.println(tmp);*/
        /*Object[] objects=set.toArray();
        System.out.println(Arrays.toString(objects));*/
    }


    public static void main1(String[] args) {
        Map<String,Integer> map=new HashMap<>();

        map.put("java",3);
        map.put("bit",2);
        map.put("hello",5);
        map.put(null,null);

        System.out.println(map);
        /*int ret=map.get("java");
        System.out.println(ret);
        System.out.println(map.get("bit2"));
        System.out.println(map.getOrDefault("java1", 6));
        Integer ret1=map.remove("bit");
        System.out.println(ret1);
        System.out.println(map);*/
        /*Set<String> set=map.keySet();//Set这个集合当中存储的元素都是不重复的
        System.out.println(set);
        Collection<Integer> collection=map.values();
        System.out.println(collection);*/
        Set<Map.Entry<String,Integer>> set=map.entrySet();
        for (Map.Entry<String,Integer> x: set) {
            System.out.println(x.getKey()+"->"+x.getValue());
        }
        Boolean flg=map.containsKey("java");
        System.out.println(flg);
        System.out.println("========================");
        System.out.println(map.containsValue(8));
    }

}
